package hu.plajko;

import hu.plajko.parser.Add;
import hu.plajko.parser.Div;
import hu.plajko.parser.IntLiteral;
import hu.plajko.parser.Mult;
import hu.plajko.parser.ParseException;
import hu.plajko.parser.Root;
import hu.plajko.parser.SimpleNode;
import hu.plajko.parser.SimpleParser;
import hu.plajko.parser.SimpleParserVisitor;
import hu.plajko.parser.Subtract;

import java.io.StringReader;
import java.util.Locale;
import java.util.Scanner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {

	private static Logger log = LoggerFactory.getLogger(Main.class);

	public static void main(String[] args) throws ParseException {
		Locale.setDefault(Locale.ENGLISH);

		Scanner s = new Scanner(Main.class.getClassLoader().getResourceAsStream("input.txt"));

		while (s.hasNextLine()) {
			String expression = s.nextLine();

			SimpleParser parser = new SimpleParser(new StringReader(expression));
			SimpleNode node = parser.simpleExpression();
			// node.dump("");
			int result = node.jjtAccept(new SimpleParserVisitor() {

				public int visit(IntLiteral node, Object data) {
					return Integer.parseInt((String) node.jjtGetValue());
				}

				public int visit(Div node, Object data) {
					Integer result = null;
					for (int i = 0; i < node.jjtGetNumChildren(); i++) {
						if (result == null)
							result = node.jjtGetChild(i).jjtAccept(this, data);
						else
							result /= node.jjtGetChild(i).jjtAccept(this, data);
					}
					return result;
				}

				public int visit(Mult node, Object data) {
					int result = 1;
					for (int i = 0; i < node.jjtGetNumChildren(); i++) {
						result *= node.jjtGetChild(i).jjtAccept(this, data);
					}
					return result;
				}

				public int visit(Subtract node, Object data) {
					Integer result = null;
					for (int i = 0; i < node.jjtGetNumChildren(); i++) {
						if (result == null)
							result = node.jjtGetChild(i).jjtAccept(this, data);
						else
							result -= node.jjtGetChild(i).jjtAccept(this, data);
					}
					return result;
				}

				public int visit(Add node, Object data) {
					int result = 0;
					for (int i = 0; i < node.jjtGetNumChildren(); i++) {
						result += node.jjtGetChild(i).jjtAccept(this, data);
					}
					return result;
				}

				public int visit(Root node, Object data) {
					return node.jjtGetChild(0).jjtAccept(this, data);
				}

				public int visit(SimpleNode node, Object data) {
					return 0;
				}
			}, 0);

			log.info("{}={}", expression, result);
		}

		s.close();
	}
}
